package com.hoppinzq.controller;

import com.hoppinzq.bean.TestBean;
import com.hoppinzq.service.TestService;
import com.hoppinzq.service.common.UserPrincipal;
import com.hoppinzq.service.proxy.ServiceProxyFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* @title：${title}
* @author：${auther}
* @create：${nowDate?string("yyyy-MM-dd")}
* @description：controller层调用测试
*/
@RestController
public class DemoController {

	@RequestMapping(value="/test1")
	public String test1(String test){
		UserPrincipal upp = new UserPrincipal("zhangqi", "123456");
		TestService testService = ServiceProxyFactory
			.createProxy(TestService.class, "http://175.178.115.82:8811/service", upp);
		return testService.sayTest(test);
	}

	@RequestMapping(value="/test2")
	public int test2(int i,int j){
		UserPrincipal upp = new UserPrincipal("zhangqi", "123456");
		TestService testService = ServiceProxyFactory
			.createProxy(TestService.class, "http://175.178.115.82:8811/service", upp);
		return testService.getDev(i,j);
	}

	@RequestMapping(value="/test3")
	public String test3(MultipartFile file) throws IOException {
		UserPrincipal upp = new UserPrincipal("zhangqi", "123456");
		TestService testService = ServiceProxyFactory
			.createProxy(TestService.class, "http://175.178.115.82:8811/service", upp);
		return testService.fileTest(file.getInputStream());
	}

	@RequestMapping(value="/test4")
	public void test4(){
		UserPrincipal upp = new UserPrincipal("zhangqi", "123456");
		TestService testService = ServiceProxyFactory
			.createProxy(TestService.class, "http://175.178.115.82:8811/service", upp);
		TestBean testBean=new TestBean();
		testBean.setName("zhangqi");
		testBean.setAge(18);
		System.out.println(testService.getBeanName(testBean));
	}

	@RequestMapping(value="/test5")
	public String test5(){
		UserPrincipal upp = new UserPrincipal("zhangqi", "123456");
		Map headers=new HashMap();
		headers.put("traceId", "zhangqi");
		TestService testService = ServiceProxyFactory
			.createProxy(TestService.class, "http://175.178.115.82:8811/service", upp,headers);
		return testService.getTraceId();
	}
}

